package com.sofar.gems.framework.controller;

import com.sofar.gems.framework.entity.SysUser;
import com.sofar.gems.framework.entity.TrainInfo;
import com.sofar.gems.framework.service.TrainInfoService;
import com.sofar.gems.framework.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: 培训机构信息控制器
 * @company: yaorange
 * @author: 啊啊啊林
 * @version: 1.0
 * @create: 2021-09-21 20:09:21
 */
@RestController
@RequestMapping("/train")
public class TrainInfoController {
    @Autowired
    private TrainInfoService trainInfoService;

    @GetMapping
    public R<?> selectAll() {
        List<TrainInfo> all = trainInfoService.selectAll();
        return R.success(all);
    }

    /**
    * @description:创建培训机构信息
    * @param trainInfo
    * @return com.sofar.gems.framework.vo.R<?>
    * @exception
    */
    @PostMapping
    public R<?> insert(@RequestBody TrainInfo trainInfo) {
        int i = trainInfoService.insertSelective(trainInfo);
        if (i > 0) {
            return R.success("success");
        } else {
            return R.error("插入失败");
        }
    }

/**
* @description: 主键删除
* @param trainId
* @return com.sofar.gems.framework.vo.R<?>
* @exception
*/
    @DeleteMapping("/{trainId}")
    public R<?> delete(@PathVariable Integer trainId ) {
        int i = trainInfoService.deleteByPrimaryKey(trainId);
        if (i > 0) {
            return R.success("success");
        } else {
            return R.error("删除失败");
        }
    }
/**
* @description:非全参修改
* @param trainInfo
* @return com.sofar.gems.framework.vo.R<?>
* @exception
*/
    @PutMapping
    public R<?> update(@RequestBody TrainInfo trainInfo) {
        int i = trainInfoService.updateByPrimaryKeySelective(trainInfo);
        if (i > 0) {
            return R.success("修改成功");
        } else {
            return R.error("修改失败");
        }
    }
}
